package app.caihan.wanandroid.ui.me

import android.os.Bundle
import androidx.lifecycle.Observer
import app.caihan.scframe.constant.DEBUG_TAG
import app.caihan.scframe.databind.DataBindingConfig
import app.caihan.scframe.ktx.nav
import app.caihan.scframe.ktx.navigateAction
import app.caihan.scframe.ktx.singleAction
import app.caihan.scframe.util.StatusBarConfig
import app.caihan.wanandroid.BR
import app.caihan.wanandroid.R
import app.caihan.wanandroid.base.WanBaseFragment
import app.caihan.wanandroid.ui.article.ArticleListUi
import app.caihan.wanandroid.ui.integral.MyIntegralActivity
import com.blankj.utilcode.util.LogUtils

/**
 *
 *
 * @author Seven-C
 * @date 2020/8/22
 */
class MeFragment : WanBaseFragment<MeFragmentModel>() {


    companion object {
        fun newInstance(): MeFragment {
            return MeFragment()
        }
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(BR.vm).addBindingParam(BR.click, ProxyClick())
    }

    override fun bindLayoutId(): Int {
        return R.layout.fragment_me
    }

    override fun getStatusBarConfig(): StatusBarConfig? {
        return StatusBarConfig(false,R.color.colorMain)
    }

    override fun initView(savedInstanceState: Bundle?) {
    }

    override fun lazyLoadData() {
    }

    override fun createObserver() {
        LogUtils.dTag(
            DEBUG_TAG,
            "${javaClass.simpleName} :: createObserver appColor = ${appViewModel.appColor.value}"
        )
        appViewModel.run {
            userInfo.observeInFragment(this@MeFragment, Observer {
                LogUtils.dTag(
                    DEBUG_TAG,
                    "${javaClass.simpleName} :: observe appViewModel.userinfo = $it"
                )
            })
            appColor.observeInFragment(this@MeFragment, Observer {
                LogUtils.dTag(
                    DEBUG_TAG,
                    "${javaClass.simpleName} :: observe appViewModel.appColor = $it"
                )
            })
        }
    }


    inner class ProxyClick {

        /** 登录 */

        fun login() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,login")
                nav().navigateAction(R.id.action_tab_to_login)
            }
        }

        /** 收藏 */
        fun collect() {
            singleAction {
                ArticleListUi.startArticleList(this@MeFragment.requireActivity())
            }
        }

        /** 积分 */
        fun integral() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,integral")
                MyIntegralActivity.startMyIntegralActivity(this@MeFragment.requireActivity())
            }
        }

        /** 文章 */
        fun ariticle() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,ariticle")
//            nav().jumpByLogin {
//                it.navigateAction(R.id.action_mainfragment_to_ariticleFragment)
//            }
            }
        }

        fun todo() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,todo")
//            nav().jumpByLogin {
//                it.navigateAction(R.id.action_mainfragment_to_todoListFragment)
//            }
            }
        }

        /** 玩Android开源网站 */
        fun about() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,about")
//            nav().navigateAction(R.id.action_to_webFragment, Bundle().apply {
//                putParcelable(
//                    "bannerdata",
//                    BannerResponse(
//                        title = "玩Android网站",
//                        url = "https://www.wanandroid.com/"
//                    )
//                )
//            })
            }
        }

        /** 加入我们 */
        fun join() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,join")
//            joinQQGroup("9n4i5sHt4189d4DvbotKiCHy-5jZtD4D")
            }
        }

        /** 设置*/
        fun setting() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,setting")
//            nav().navigateAction(R.id.action_mainfragment_to_settingFragment)
            }
        }

        /**demo*/
        fun demo() {
            singleAction {
                LogUtils.dTag(DEBUG_TAG, "ProxyClick,demo")
//            nav().navigateAction(R.id.action_mainfragment_to_demoFragment)
            }
        }
    }

}